from flask import Blueprint,jsonify
from flask_restful import Api,Resource,fields,marshal
from common.models.users import *
import json

vip_bp = Blueprint('vip_bp',__name__,url_prefix='/vip')
api = Api(vip_bp)
vip_fields = {
    'level':fields.Integer,
    'price':fields.String,
    'vip_cour':fields.Integer,
    'exempt_cour':fields.Integer,
    'save':fields.Integer,
    'environment':fields.Integer,
    'ssh':fields.Integer,
    'web_ide':fields.Integer,
    'discounts':fields.Integer,
    'exempt_study':fields.Integer
}

class VipGet(Resource):
    def get(self):
        vips_info = Vip.query.all()
        result = {}
        for i in vips_info:
            if i.level == 0:
                common_user_list = json.loads(json.dumps(marshal(i,vip_fields)))
                common_user_list['level']='免费'
                result['common_user_list'] = common_user_list
            if i.level == 1:
                common_vip_list = json.loads(json.dumps(marshal(i, vip_fields)))
                common_vip_list['level']='普通会员'
                result['common_vip_list'] = common_vip_list
            if i.level == 2:
                expert_vip_list = json.loads(json.dumps(marshal(i, vip_fields)))
                expert_vip_list['level']='高级会员'
                result['expert_vip_list'] = expert_vip_list

        return jsonify(code=200,msg='ok',data=result)




api.add_resource(VipGet,'/get_vip_list')